#coding:utf-8
import threading

class LObject:
    def __init__(self,name):
        if(self.__class__==LObject):
            raise NotImplementedError,"base class LObject can not be created"
        self._name=name

    def __str__(self):
        return self._name

class Cache(LObject):
    def __init__(self,name,size):
        if(self.__class__==Cache):
            raise NotImplementedError, "cache is abstarct class"
        LObject.__init__(self,name)
        self._size=size
        self._cursize=0
        self._lock=threading.RLock()

    def get(self,key):
        raise NotImplementedError, "abstract method"

    def add(self,key,value):
        #lock=threading.RLock()
        self._lock.acquire()
        if(self._size>self._cursize):
            self.set(key,value)
            self._cursize+=1
        else:
            pass
        self._lock.release()

    def set(self,key,value):
        raise NotImplementedError, "abstract method"        


class DictCache(Cache):
    def __init__(self,name="dict cache",size=0):
        self._cache={}
        Cache.__init__(self,name,size)

    def get(self,key):
        return self._cache.get(key,None)

    def set(self,key,value):
        self._cache[key]=value

class PostProcesser(LObject):
    def __init__(self,name):
        if(self.__class__==PostProcesser):
            raise NotImplementedError,"postprocess can not be created, abstarct class"
        LObject.__init__(self,name)

    def process(self,url,info,content):
        if(self.__class__==PostProcess):
            raise NotImplementedError,"postprocess can not be created, abstarct class"
